# _*_coding:utf-8 _*_
# @Time　　:2021/6/21 22:33
# @Author : mojin
# @Email : 397135766@qq.com
# @File　　  :run.py
# @Software  :PyCharm
from multiprocessing import Pool
from common.read_yaml import ReadYaml
import os, shutil
import pytest
from common.app_info import get_device_infos, uninstall_app
from common.appium_auto_server import close_appium


def run_parallel(device_info):
    pytest.main([f"--cmdopt={device_info}", '%s' % device_info[1]['test_case_path'], "-vs", "--alluredir",
                 "target/allure-results"])
    os.system('allure generate ./target/allure-results -o ./target/allure-report --clean')


def run():
    try:
        shutil.rmtree("./target")  # 删除报告目录，删除后只能看到当前执行后的报告结果，不删除能看到执行的历史执行结果
    except:
        pass

    close_appium()
    device_lists = get_device_infos()
    uninstall_app(device_lists)
    with Pool(len(device_lists)) as pool:
        pool.map(run_parallel, device_lists)
        pool.close()
        pool.join()

    close_appium()


if __name__ == "__main__":
    run()
